//
//  SYS_TitleAndImageView.m
//  System_App
//
//  Created by czy001 on 2017/12/1.
//  Copyright © 2017年 czy001. All rights reserved.
//

#import "SYS_TitleAndImageView.h"

@implementation SYS_TitleAndImageView

//图片高度和字体大小
- (id)initWithFrame:(CGRect)frame withImageHeight:(CGSize)size andTitleFont:(float)fontSize andIsVetical:(BOOL)flag
{
    self=[super initWithFrame:frame];
    if (self) {
        
        float width=frame.size.width;
        
        if (flag) {
            _photo=[[UIImageView alloc] initWithFrame:CGRectMake((width-size.width)/2, 5, size.width, size.height)];
            [self addSubview:_photo];
            
            _title=[[UILabel alloc] initWithFrame:CGRectMake(0, _photo.frame.origin.y+_photo.frame.size.height+5, width, 20)];
            _title.font=[UIFont systemFontOfSize:fontSize];
            _title.textAlignment=NSTextAlignmentCenter;
            [self addSubview:_title];
        }
        else
        {
            CGFloat mariginWidth=(frame.size.width-60-size.width-10)/2;
            _photo=[[UIImageView alloc] initWithFrame:CGRectMake(mariginWidth, 10, size.width, size.height)];
            [self addSubview:_photo];
            
            _title=[[UILabel alloc] initWithFrame:CGRectMake(mariginWidth+size.width+10, _photo.center.y-10, 60, 20)];
            _title.font=[UIFont systemFontOfSize:fontSize];
//            _title.textAlignment=NSTextAlignmentCenter;
            [self addSubview:_title];
        }
        
        _badge=[[UILabel alloc] initWithFrame:CGRectMake(size.width-1, -5, 20, 20)];
        _badge.backgroundColor=[UIColor redColor];
        _badge.textColor=[UIColor whiteColor];
        _badge.layer.cornerRadius=10;
        _badge.font=[UIFont systemFontOfSize:12];
        _badge.textAlignment=NSTextAlignmentCenter;
        _badge.layer.masksToBounds=YES;
        _badge.hidden=YES;
        [_photo addSubview:_badge];
        
    }
    
    return self;
}

//设置颜色
- (void)setTextColor:(UIColor *)textColor
{
    _textColor=textColor;
    _title.textColor=_textColor;
}

//设置文字
- (void)setText:(NSString *)text
{
    _title.text=text;
}

//设置图标
- (void)setImage:(UIImage *)image
{
    _photo.image=image;
}

//设置角标
- (void)setBadgeNum:(int)badgeNum
{
    if (badgeNum>0) {
        _badge.hidden=NO;
        _badge.text=[NSString stringWithFormat:@"%i",badgeNum];
    }
    else
    {
        _badge.hidden=YES;
    }
}


@end
